
package com.udc.medLine.transaction;

import java.util.List;

import com.udc.medLine.entity.CondicaoVO;
import com.udc.medLine.entity.Funcionario;
import com.udc.medLine.entity.Marca;
import com.udc.medLine.factory.FactoryFuncionario;
import com.udc.medLine.factory.FactoryMarca;
import com.udc.medLine.persistence.Bd;

public class TransactionMarca {

	private Marca marca;
	private List listMarca;
	private Bd banco;
	
	/**
	 * 
	 */
	public TransactionMarca() {
		super();
		marca = new Marca();
		try{
			banco = Bd.getInstance();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		// TODO Stub de construtor gerado automaticamente
	}

	public Marca getMarca() {
		return marca;
	}

	public void setMarca(Marca new_marca) {
		this.marca = new_marca;
	}

	public void remover(Marca nMarca) throws Exception {
		banco.beginTransaction();
			FactoryMarca factory = new FactoryMarca();
			marca.setId(nMarca.getId());
			factory.setMarca(marca);
			factory.delete();
		banco.commit();
	}

	public void inserir(Marca nMarca) throws Exception {
		banco.beginTransaction();
			FactoryMarca factory = new FactoryMarca();			
			marca.setNome(nMarca.getNome());
			factory.setMarca(marca);
			factory.insert();
		banco.commit();
	}

	public void atualizar(Marca nMarca) throws Exception {
		banco.beginTransaction();
			FactoryMarca factory = new FactoryMarca();
			marca.setId(nMarca.getId());
			marca.setNome(nMarca.getNome());
			factory.setMarca(marca);
			factory.update();
		banco.commit();
	}


	public void obterMarca(String campo, String valor) throws Exception{
		banco.beginTransaction();
			FactoryMarca factory = new FactoryMarca();
			factory.setMarca(new Marca());
			listMarca = factory.getMarca(campo,valor);
		banco.commit();
	}
	
	public void obterListaMarca() throws Exception{
		banco.beginTransaction();
			FactoryMarca factory = new FactoryMarca();
			factory.setMarca(new Marca());
			listMarca = factory.getListaMarca();
		banco.commit();
	}
	
	public void obterMarca(Marca nMarca) throws Exception{
		banco.beginTransaction();
			FactoryMarca factory = new FactoryMarca();
			marca.setId(nMarca.getId());
			factory.setMarca(marca);
			marca = factory.obterMarca();
		banco.commit();
	}
	
	/**
	 * @return
	 */
	public List getListMarca() {
		return listMarca;
	}

	/**
	 * @param list
	 */
	public void setListMarca(List list) {
		listMarca = list;
	}

	public List<Marca> search(CondicaoVO condicao) throws Exception {
		banco.beginTransaction();
		FactoryMarca factory = new FactoryMarca();
		listMarca = factory.search(condicao);
		banco.commit();
		return listMarca;
	}

}
